package com.xingxin.controller;


import com.xingxin.entity.Permission;
import com.xingxin.service.PermissionService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mrLiu
 * @since 2021-01-08
 */
@RestController
@RequestMapping("/rights")
public class PermissionApiController extends BaseController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("/list")
    @ResponseBody
    public Map<String, Object> queryRightsList() {
        logger.info("==>PermissionApiController--queryRightsList--start,");
        Map<String, Object> data = new HashMap<>();
        try {
            List<Permission> result = permissionService.list();
            if (CollectionUtils.isNotEmpty(result)) {
                result.sort(Comparator.comparing(Permission::getPsLevel).thenComparing(Permission::getPsId));
            }
            data.put("result", result);
        } catch (Exception e) {
            logger.error("==>PermissionApiController--queryRightsList--Exception is : {}", e);
        }
        return resultMap("0", "success", data);
    }
}

